"use strict";

// content :ctx+'/bus/vaccineManage/form?id='+id,
function viewDetail(id){
    var title = "疫苗"
    if(id!=""){
        title = "修改"+title;
    }else{
        title = "新增"+title;
    }

    layer.open({
        type : 2,
        fix : true,
        skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
        move : [ '.layui-layer-title', true ],
        title : [ title, 'font-family: Arial Negreta; font-size:20px; font-weight: 700; color:#33A5E7;'],
        offset : [ '30px' ],
        area : [ '620px', '415px'],
        maxmin : false,
        closeBtn : 1,
        // content:  ctx+'/shop/detail?id='+id,

        //重点 这个是 弹出页面链接
        content:  ctx+'/bus/vaccineManage/form?id='+id,



        btn : '保存', /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            var innerObj = window[layero.find('iframe')[0]['name']];
            innerObj.$("#inputForm").submit();
            return false;
        }
    });
}

/*
* 新增和编辑商品
* */
function editGoods(id){
     var title = id !="" ? "编辑商品":"新增商品";
    layer.open({
        type : 2,
        fix : true,
        skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
        move : [ '.layui-layer-title', true ],
        title : [ title, 'font-family: Arial Negreta; font-size:20px; font-weight: 700; color:#33A5E7;'],
        offset : [ '30px' ],
        area : [ '820px', '615px'],
        maxmin : false,
        closeBtn : 1,
        // content:  ctx+'/shop/detail?id='+id,
        content:  ctx+'/app/goods2/form?id='+id,
        btn : '保存', /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            var innerObj = window[layero.find('iframe')[0]['name']];
            innerObj.$("#inputForm").submit();
            return false;
        }
    });
}
/*
* 商家查看商品详情
*
* */
function viewGoods(id){

    // alert(111111111);
    //
    //
    // console.log(12221323);
    // console.log(12221323,22222,3333,4444);
    // console.log({},22222,3333,4444);
     var title ="查看商品详情";
    layer.open({
        type : 2,
        fix : true,
        skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
        move : [ '.layui-layer-title', true ],
        title : [ title, 'font-family: Arial Negreta; font-size:20px; font-weight: 700; color:#33A5E7;'],
        offset : [ '30px' ],
        area : [ '820px', '615px'],
        maxmin : false,
        closeBtn : 1,
        // content:  ctx+'/shop/detail?id='+id,
        content:  ctx+'/app/goods2/view?id='+id,
        btn : ['关闭'], /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            layer.close(index);
        }
    });
}











"use strict";

var order = {
    "orderAmount":13.5
    ,"orderGoodsList":
        [
            {
                "name":'苹果',
                "price":15.69,
                "goodsId":'725674162412060672',
            },
            {
                "name":'苹果',
                "price":8.29,
                // "id":'725674162412060672',
            }
        ]
};
order ={};
/*
* 在商品列表页面 进行下单
*
* */
function saveOrder(goodsId){
    // jQuery 框架 提供的 $
    $.ajax({
        url: ctx + "/app/order2/saveOrder1",
        type: "post",
        data: JSON.stringify(order),
        contentType: "application/json;charset=UTF-8",
        async : false,
        success : function(result) {
            order = {};
            if(result.code== 0){
                layer.msg("保存成功！", {icon: 1, time: 1000}, function (){
                    // parent.window.location.reload();
                })
            }else{
                layer.msg("商品信息,保存失败！", {icon: 1, time: 1000}, function (){
                    // parent.window.location.reload();
                })
            }
        },
        error: function (e) {
            layer.msg(e, {icon: 5});
        }
    });
}


function addCart(price,name){
    // order.orderGoodsList.push({price,name});
    order.orderGoodsList || (order.orderGoodsList = []);
    // if(!order.orderGoodsList){
    //     order.orderGoodsList = [];
    // }
    order.orderAmount || (order.orderAmount = 0.00);
    order.orderGoodsList.push({price:price,name:name});
    order.orderAmount +=  parseFloat(price);

    console.log(order)

}




/*
 *疫苗企业新增/编辑
 * my
 */
function entVaccineAdd(id) {
    var title = "", url = ctx + '/ent/entVaccine/form';
    if (id) {
        title = "修改" + title;
        url += "?id=" + id;
    } else {
        title = "新增" + title;
    }
    layer.open({
        type : 2,
        fix : true,
        //skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
        move : [ '.layui-layer-title', true ],
        title : [ title, 'font-size:16px;font-weight: 400;color:#ffffff;background-color:#2FA4E7;' ],
        offset : [ '30px' ],
        area : [ '70%', '70%' ],
        maxmin : false,
        closeBtn : 1,
        content : url,
        btn : [ '保存', '取消' ], /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            var innerObj = window[layero.find('iframe')[0]['name']];
            innerObj.$("#inputForm").submit();
            return false;
        },
        btn2 : function(index, layero) {
            layer.close(index);
        }
    });
}





/*
 *疫苗企业查看
 * my
 */
function entVaccineView(id) {
    layer.open({
        type : 2,
        fix : true,
        //      skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
        move : [ '.layui-layer-title', true ],
        title : [ '查看', 'font-size:16px;font-weight: 400;color:#ffffff;background-color:#2FA4E7;' ],
        offset : [ '30px' ],
        area : [ '65%', '70%' ],
        maxmin : false,
        closeBtn : 1,
        content : ctx + '/ent/entVaccine/entVaccineView?id='+ id,
        btn :  '关闭', /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            layer.close(index);
        }
    });
}
/*
 *动态添加行
 * my
*/
function rowAdd(id) {
    var row =  parseInt($("#contentTable").find("tr").length);
    if(row>1){
        $("#msg").html("");
    }
    $("#contentTable tr:last").after(
        '<tr>'+
        '<td ></td>'+
        '<td ><input name="orderGoodsList[].name" htmlEscape="false" maxlength="20" class="input-xlarge per-name" required="required" style="width:220px;height:25px;"/></td>'+
        '<td ><input name="orderGoodsList[].price" htmlEscape="false" maxlength="11" class="input-xlarge per-price" required="required" style="width:220px;height:25px;" onBlur="checkPhone()"/></td>'+
        '<td ><input name="orderGoodsList[].stock" htmlEscape="false" maxlength="11" class="input-xlarge per-stock" required="required" style="width:220px;height:25px;" onBlur="checkPhone()"/></td>'+
        '<td ><a href="javascript:;" onclick="rowDelete(this)">删除</a></td>'+
        '</tr>'
    );
    changeIndex();
}
/*
 *动态删除行
 * my
 */
function rowDelete(obj) {
    if($("#contentTable").find("tr").length<3){
        $("#msg").html("必填项，不能删除！");
    }else{
        $(obj).parent().parent().remove();
        changeIndex();
    }
}
/*
 *排序
 * my
 */
function changeIndex(){
    //解决首列排序号
    $("#contentTable").find("tr").each(function (i,n) {
        $(n).find("td:eq(0)").text(i);
    });

    $(".per-name").each(function (i,n) {
        $(n).attr("name",'orderGoodsList['+i+'].name');
    });
    $(".per-price").each(function (i,n) {
        $(n).attr("name",'orderGoodsList['+i+'].price');
    });
    $(".per-stock").each(function (i,n) {
        $(n).attr("name",'orderGoodsList['+i+'].stock');
    });

}

/*
*手机号码校验
* my
*/
function checkPhone() {
    var valid_rule =/^1(3|4|5|6|7|8|9)\d{9}$/;// 手机号码校验规则
    var flag = 0;
    $(".per-phone").each(function (i,n) {
        if('' == ($(n).val() || '')){
            // $("#msg").html("请填写手机号码！");
            flag = 0;
        }else{
            $("#msg").html("");
            if(!valid_rule.test($(n).val())){
                layer.msg("手机号码有误，请重填写!", {
                    icon : 2,
                    time : 1000
                });
                flag = 0;
            }else{
                flag = 1;
            }
        }
    });
    return flag;
}
